<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JSONP-demo</title>
</head>
<body>
<button>jsonp获取数据</button>
<p>hello world</p>
<script>
let btn = document.getElementsByTagName('button')[0]
let p = document.getElementsByTagName('p')[0]

function myFunction (data) {
    p.innerHTML = data.message
}

btn.addEventListener('click',function(){
    let script = document.createElement('script')
    script.src = "http://localhost:3001?callback=myFunction"
    document.documentElement.appendChild(script)
})
</script>
</body>
</html>